<template>
  <h3>Child</h3>
  <p>{{title}}</p>
  <p>{{msg}}</p>
  <p>{{ob}}</p>
  <button @click="update">点击获取数据</button>
  <button @click="transfer">传递数据</button>
</template>

<script>
export default {
  name: "Child",
  data(){
    return{
        msg:{
          name:"dsada",
          age:"son"
       }
    }
  },
  //数组和对象必须通过工厂模式
  // props:["title","msg","ob"]//接受组件的参数关键字,可以接受任何类型
  props:{
    title:{
      type:String,
      required:true//必选项
    },
    msg:{
      type:String
    },
    ob:{
      type:Object,
      default(){
        return {
         "name": " ", "age": '', "stu": "" //对象和数组传递需要用方法
        }
      }
    }
  },
  methods:{
    update(){
      console.log(this.title);
    },
    transfer(){
      console.log("子传父")
      this.$emit("sonToFather",this.msg)
    }
  }
}
</script>

<style scoped>

</style>
